Forcedly Call Javascript from Webpart
When developing web parts or other SharePoint controls many times we might require to call some functions on body onload event.
As web part does not contain body tag we cannot use onload attribute of body tag.
To overcome this drawback, a developer can use an array i.e. _spBodyOnLoadFunctionNames
The only thing we need to do is to pass the function's name using .push method.
Example:
<script language="javascript">
_spBodyOnLoadFunctionNames.push("TestFunction");
function TestFunction()
{
alert("hello");
}
</script>
We can use above script in master page, aspx page, content editor web part, visual web part as per the need.
As web part does not contain body tag we cannot use onload attribute of body tag.
To overcome this drawback, a developer can use an array i.e. _spBodyOnLoadFunctionNames
The only thing we need to do is to pass the function's name using .push method.
Example:
<script language="javascript">
_spBodyOnLoadFunctionNames.push("TestFunction");
function TestFunction()
{
alert("hello");
}
</script>
We can use above script in master page, aspx page, content editor web part, visual web part as per the need.
Forcedly Call Javascript from Webpart
Reviewed by
Srikant N
on
Tuesday, April 26, 2016
Rating:
No comments :
Thanks for your time ! Have a great day.